/*
 ----------------------------------------------------------------------------------
                          "THE BEER-WARE COPYRIGHT LICENSE"
                                    (Revision 43)
                                     -----------
   Rymek [rymek@rymek.org] wrote this file. As long as You retain this notice and
   this file has been sent directly to You by the author, You can do whatever You
   want with this stuff as long as You don't sell or rent it. If we meet some day,
   and You think this stuff is worth it, You can buy me a beer in return :-)
                                                                __________
                                                                Paweł Rymaszewski
 ----------------------------------------------------------------------------------
 */

package utils.properties;

import constants.Constants;
import constants.UiConstants;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

/**
 * Holds program configuration as static objects
 *
 * @author rymek
 *         User: rymek
 *         Date: 27.07.11
 *         Time: 10:08
 */
public class Configuration {

    public static GeneralProperties generalProperties;  // holds app specific configuration
    public static ServerProperties serverProperties;    // server properties
    public static boolean production;                   // determines if connection is established to PROD environment

    // date and time formatters
    public static final DateFormat dateFormat = new SimpleDateFormat(Constants.DATE_FORMAT);
    public static final DateFormat timeFormat = new SimpleDateFormat(Constants.TIME_FORMAT);
    public static final DateFormat dttmFormat = new SimpleDateFormat(Constants.DTTM_FORMAT);
    public static final DateFormat dttmFileFormat = new SimpleDateFormat(Constants.DTTM_FILE_FORMAT);

    // Icon objects
    public static Image ICON_DEFAULT_FRAME;
    public static ImageIcon ICON_CONNECT;
    public static ImageIcon ICON_SEARCH;
    public static ImageIcon ICON_STOP;
    public static ImageIcon ICON_SAVE;
    public static ImageIcon ICON_MERGE;

    /**
     * Constructor.
     * Also loads all settings.
     *
     * @throws IOException when configuration cannot be read
     */
    public Configuration() throws IOException {

        generalProperties = new GeneralProperties();
        serverProperties = new ServerProperties();
        this.loadIcons();
    }

    /**
     * Creates static ICON objets to use in app
     */
    private void loadIcons() {

        ICON_DEFAULT_FRAME = new ImageIcon(getClass().getClassLoader().getResource(UiConstants.ICON_DEFAULT_FRAME)).getImage();
        ICON_CONNECT = new ImageIcon(new ImageIcon(getClass().getClassLoader().getResource(UiConstants.ICON_CONNECT)).getImage().getScaledInstance(UiConstants.ICON_SIZE_X, UiConstants.ICON_SIZE_Y, java.awt.Image.SCALE_SMOOTH));
        ICON_SEARCH = new ImageIcon(new ImageIcon(getClass().getClassLoader().getResource(UiConstants.ICON_SEARCH)).getImage().getScaledInstance(UiConstants.ICON_SIZE_X, UiConstants.ICON_SIZE_Y, java.awt.Image.SCALE_SMOOTH));
        ICON_STOP = new ImageIcon(new ImageIcon(getClass().getClassLoader().getResource(UiConstants.ICON_STOP)).getImage().getScaledInstance(UiConstants.ICON_SIZE_X, UiConstants.ICON_SIZE_Y, java.awt.Image.SCALE_SMOOTH));
        ICON_SAVE = new ImageIcon(new ImageIcon(getClass().getClassLoader().getResource(UiConstants.ICON_SAVE)).getImage().getScaledInstance(UiConstants.ICON_SIZE_X, UiConstants.ICON_SIZE_Y, java.awt.Image.SCALE_SMOOTH));
        ICON_MERGE = new ImageIcon(new ImageIcon(getClass().getClassLoader().getResource(UiConstants.ICON_MERGE)).getImage().getScaledInstance(UiConstants.ICON_SIZE_X, UiConstants.ICON_SIZE_Y, java.awt.Image.SCALE_SMOOTH));
    }
}
